import * as THREE from "three";

const SPEED = 0.01;
export default class Carousel {
  constructor() {
    this.rotation = 0;

    this.models = [];
    this.main = new THREE.Group();
  }

  add(mesh) {
    this.models.push(mesh);
  }

  build() {
    const defaultPosition = this.models[0].position.clone();
    const nums = 6;
    const radius = Math.PI * 2 / nums;
    this.models.map(model => {
      model.position.set(0, 0, 0);
      this.main.add(model);
      for (let i = 1; i < nums; i++) {
        const n = model.clone();
        n.rotation.set(0, 0, radius * i);
        this.main.add(n);
      }
    });
    this.main.position.copy(defaultPosition);
  }

  update() {
    this.rotation += SPEED;
    this.main.rotation.z = this.rotation;
  }
}